cmake_minimum_required(VERSION 3.10)
project(benxdb)

set(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")

# PCL
find_package(PCL 1.8 COMPONENTS common io)
if (PCL_FOUND)
    include_directories(${PCL_INCLUDE_DIRS})
    link_directories(${PCL_LIBRARY_DIRS})
    add_definitions(${PCL_DEFINITIONS})
endif (PCL_FOUND)

include_directories(include)

find_package(Threads)
find_package(ZLIB)

add_definitions(-DNDEBUG)

message(gtest_include_dir=${GTEST_INCLUDE_DIR})
message(gtest_library=${GTEST_LIBRARY})
message(threads=${CMAKE_THREAD_LIBS_INIT})

include_directories(${GTEST_INCLUDE_DIR})

aux_source_directory(src/type TYPE_DIR_SRCS)
add_library(type ${TYPE_DIR_SRCS})

aux_source_directory(src/common COMMON_DIR_SRCS)
add_library(common ${COMMON_DIR_SRCS})

aux_source_directory(src/compress COMPRESS_DIR_SRCS)
add_library(compress ${COMPRESS_DIR_SRCS})
target_link_libraries(compress PUBLIC common ZLIB::ZLIB)

aux_source_directory(src/storage/disk STORAGE_DISK_DIR_SRCS)
add_library(storage_disk ${STORAGE_DISK_DIR_SRCS})
target_link_libraries(storage_disk common compress)

aux_source_directory(src/catelog CATELOG_DIR_SRCS)
add_library(catelog ${CATELOG_DIR_SRCS})

aux_source_directory(src/storage STORAGE_DIR_SRCS)
add_library(storage ${STORAGE_DIR_SRCS} ${STORAGE_DISK_DIR_SRCS})
target_link_libraries(storage common compress)

# TODO change to index dir
aux_source_directory(src/index INDEX_DIR_SRCS)
add_library(index ${INDEX_DIR_SRCS})
target_link_libraries(index common type)

aux_source_directory(src/mem MEM_DIR_SRCS)
add_library(mem ${MEM_DIR_SRCS})
target_link_libraries(mem storage common type index)

aux_source_directory(src/access ACCESS_DIR_SRCS)
add_library(benxdb ${ACCESS_DIR_SRCS})
target_link_libraries(benxdb mem storage type catelog common stdc++fs)
if(PCL_FOUND)
    target_link_libraries(benxdb ${PCL_LIBRARIES})
endif(PCL_FOUND)

file(COPY config.ini DESTINATION .)

# Test
add_subdirectory(test)
# Benchmark
add_subdirectory(benchmark)